﻿Public Class Dsubmodulo

    Public Shared Function SeleccionarTodoXModulo(ByVal descEmpresa As String, ByVal idModulo As Int32, ByVal idPerfil As Int32) As List(Of EsubModulo)
        Dim submodulos As List(Of EsubModulo) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_subModulo_selXModulo", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idModulo", SqlDbType.Int).Value = idModulo
                cmd.Parameters.Add("@idPerfil", SqlDbType.Int).Value = idPerfil
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            submodulos = New List(Of EsubModulo)
                            Dim submodulo As EsubModulo = Nothing
                            Do While dr.Read
                                submodulo = New EsubModulo( _
                                    dr.GetInt32(dr.GetOrdinal("idModulo")), _
                                    dr.GetInt32(dr.GetOrdinal("idSubModulo")), _
                                    dr.GetString(dr.GetOrdinal("descSubModulo")), _
                                    dr.GetString(dr.GetOrdinal("direccionUrl")))
                                submodulos.Add(submodulo)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return submodulos
    End Function
    Public Shared Function SeleccionarTodoXModuloProyecto(ByVal descEmpresa As String, ByVal idModulo As Int32, ByVal idPerfil As Int32, ByVal Ruta As String) As List(Of EsubModulo)
        Dim submodulos As List(Of EsubModulo) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_subModulo_selXModuloProyecto", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idModulo", SqlDbType.Int).Value = idModulo
                cmd.Parameters.Add("@idPerfil", SqlDbType.Int).Value = idPerfil
                cmd.Parameters.Add("@Ruta", SqlDbType.VarChar, 500).Value = Ruta
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            submodulos = New List(Of EsubModulo)
                            Dim submodulo As EsubModulo = Nothing
                            Do While dr.Read
                                submodulo = New EsubModulo( _
                                    dr.GetInt32(dr.GetOrdinal("idModulo")), _
                                    dr.GetInt32(dr.GetOrdinal("idSubModulo")), _
                                    dr.GetString(dr.GetOrdinal("descSubModulo")), _
                                    dr.GetString(dr.GetOrdinal("direccionUrl")))
                                submodulos.Add(submodulo)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return submodulos
    End Function
End Class

